package com.smart.community.region.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 区域树视图对象
 * 
 * @author Wu.Liang
 * @since 2024-12-21
 */
@Data
@Schema(description = "区域树视图对象")
public class RegionTreeVO implements Serializable {

    private static final long serialVersionUID = 1L;

    @Schema(description = "区域ID")
    private Long id;

    @Schema(description = "区域编码")
    private String regionCode;

    @Schema(description = "区域名称")
    private String regionName;

    @Schema(description = "父区域ID")
    private Long parentId;

    @Schema(description = "区域层级：1-5")
    private Integer regionLevel;

    @Schema(description = "区域类型：1-省，2-市，3-区县，4-街道，5-社区")
    private Integer regionType;

    @Schema(description = "区域类型文本")
    private String regionTypeText;

    @Schema(description = "面积（平方公里）")
    private BigDecimal area;

    @Schema(description = "人口数量")
    private Integer population;

    @Schema(description = "纬度")
    private BigDecimal latitude;

    @Schema(description = "经度")
    private BigDecimal longitude;

    @Schema(description = "状态：0-禁用，1-启用")
    private Integer status;

    @Schema(description = "状态文本")
    private String statusText;

    @Schema(description = "排序字段")
    private Integer sortOrder;

    @Schema(description = "创建时间")
    private LocalDateTime createTime;

    @Schema(description = "更新时间")
    private LocalDateTime updateTime;

    @Schema(description = "子区域列表")
    private List<RegionTreeVO> children;

    @Schema(description = "是否为叶子节点")
    private Boolean isLeaf;

    @Schema(description = "是否为顶级区域")
    private Boolean isRoot;

    // ==================== 统计字段 ====================

    @Schema(description = "社区数量")
    private Integer communityCount;

    @Schema(description = "楼栋数量")
    private Integer buildingCount;

    @Schema(description = "房户数量")
    private Integer householdCount;

    @Schema(description = "居民数量")
    private Integer residentCount;

    @Schema(description = "入住率")
    private BigDecimal occupancyRate;

    @Schema(description = "是否有子区域")
    private Boolean hasChildren;

    // ==================== 业务方法 ====================

    /**
     * 获取状态文本
     */
    public String getStatusText() {
        if (status == null) {
            return "未知";
        }
        return status == 1 ? "启用" : "禁用";
    }

    /**
     * 获取区域类型文本
     */
    public String getRegionTypeText() {
        if (regionType == null) {
            return "未知";
        }
        switch (regionType) {
            case 1:
                return "省";
            case 2:
                return "市";
            case 3:
                return "区县";
            case 4:
                return "街道";
            case 5:
                return "社区";
            default:
                return "未知";
        }
    }

    /**
     * 判断是否为叶子节点
     */
    public Boolean getIsLeaf() {
        return regionType != null && regionType == 5;
    }

    /**
     * 判断是否为顶级区域
     */
    public Boolean getIsRoot() {
        return parentId != null && parentId == 0;
    }
} 